from selenium import webdriver
from time import sleep

driver = webdriver.Firefox()
driver.maximize_window()
url = 'https://www.baidu.com/'
driver.get(url)
# 设置cookie
driver.add_cookie({
    'name': 'BDUSS',
    'value': 'nc1d054Q3ZnflFDMms5U29yZ0tGfjI2STFXUUx2V0NRYU5kNFJQRGtjTXlEbTVuRUFBQUFBJCQAAAAAAAAAAAEAAACHQjM~a2FybLPJAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAADKBRmcygUZnc'
})
sleep(3)
# 刷新页面，携带cookie，重新请求百度
driver.refresh()
# 获取cookie
# print(driver.get_cookie('BDUSS'))
# 获取所有的cookie
cookies = driver.get_cookies()
# print(cookies)
for item in cookies:
    print(item['name'])

sleep(3)
driver.quit()